package com.example.cart_system.controller;

import com.example.cart_system.pojo.MonthInfo;
import com.example.cart_system.pojo.Usr;
import com.example.cart_system.service.ChartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
public class ChartsController {
    @Autowired
    private ChartsService chartsService;
    //得到用户所有年份
    @PostMapping("/getAllYear")
    public List<String> getAllYear(@RequestBody Usr usr) {
        return chartsService.getAllYear(usr.getUsrid());
    }
    //得到所有有记录的月份
    @PostMapping("/getAllMonth")
    public List<String> getAllMonth(@RequestBody MonthInfo monthInfo) {
        return chartsService.getAllMonth(monthInfo.getUsrid(), monthInfo.getYear());
    }
    //计算日消费量
    @PostMapping("/getSum")
    public List<Map<String, Object>> getSum(@RequestBody MonthInfo monthInfo) {
        return chartsService.getSumByYearAndMonth(monthInfo.getUsrid(), monthInfo.getYear(), monthInfo.getMonth());
    }
}
